package algorithm.leetcode;

public class NO11_盛水最多的容器 {

    class PerformanceSolution {
        public int maxArea(int[] height) {
            int left = 0, right = height.length - 1;

            int max = 0;

            while (left < right) {
                max = Math.max(max, Math.min(height[left], height[right]) * (right - left));
                if (height[left] < height[right]) {
                    left++;
                } else {
                    right--;
                }
            }
            return max;
        }
    }

    class Solution {
        public int maxArea(int[] height) {
            /*
            min(hi, hj) * ads(i - j)
             */
            int max = 0;
            for (int i = 0; i < height.length; i++) {
                for (int j = i + 1; j < height.length; j++) {
                    max = Math.max(max, Math.min(height[i], height[j]) * (j - i));
                }
            }
            return max;
        }
    }
}
